package com.wondream.jenkins.controller;

import com.wondream.jenkins.service.JenkinsService;
import com.wondream.jenkins.model.BuildResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author wangjun
 * @note Jenkins自动化
 * @date 2024-05-31  11:58
 * @eo.api-type http
 * @eo.groupName 系统管理.018Jenkins自动化
 * @eo.path
 */
@Api(tags = "Jenkins自动化")
@RestController
public class JenkinsController {

    @Autowired
    private JenkinsService jenkinsService;

    /**
     * @eo.name 101.集成
     * @eo.url /jenkins/buildJob
     * @eo.method get
     * @eo.request-type formdata
     * @return ResponseResult
     */
    @ApiOperation("101.集成")
    @GetMapping("/jenkins/buildJob")
    public void buildJob(String jobName) {
        jenkinsService.buildJob(jobName);
    }

    /**
     * @eo.name 102.根据队列url查询结果
     * @eo.url /jenkins/queryJobByQueueUrl
     * @eo.method get
     * @eo.request-type formdata
     * @return ResponseResult
     */
    @ApiOperation("102.根据队列url查询结果")
    @GetMapping("/jenkins/queryJobByQueueUrl")
    public BuildResult queryJobByQueueUrl(String jobName, String url) {
        return jenkinsService.queryJobByQueueUrl(jobName, url);
    }

    /**
     * @eo.name 103.根据构建url查询结果
     * @eo.url /jenkins/queryJobByBuildUrl
     * @eo.method get
     * @eo.request-type formdata
     * @return ResponseResult
     */
    @ApiOperation("103.根据构建url查询结果")
    @GetMapping("/jenkins/queryJobByBuildUrl")
    public BuildResult queryJobByBuildUrl(String jobName, String url) {
        return jenkinsService.queryJobByBuildUrl(jobName, url);
    }
}
